package com.xzy.product_service.service.impl;

import com.xzy.product_service.domain.Product;
import com.xzy.product_service.service.ProductService;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ProductServiceImpl implements ProductService {
    private static final Map<Integer,Product> map=new HashMap<>();
    static {
        Product p1=new Product(1,"香蕉",4322,123);
        Product p2=new Product(2,"梨",234,23);
        Product p3=new Product(3,"苹果",12432,43);
        Product p4=new Product(4,"西红柿",434,234);
        Product p5=new Product(5,"洋葱",4353,432);
        map.put(1,p1);
        map.put(2,p2);
        map.put(3,p3);
        map.put(4,p4);
        map.put(5,p5);
    }
    @Override
    public List<Product> productList() {
        Collection<Product> values = map.values();
        return new ArrayList<>(values);
    }

    @Override
    public Product findById(Integer id) {
        return map.get(id);
    }
}
